﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(Page.IsPostBack != true) {
            cbxFilter.Checked = true;
            cbxFilter_CheckedChanged(sender, e);
           /* Label3.Text = "Выбрано: " + gvApAtlas.Rows.Count; */
        }
    }
    protected void dsApAtlas_Selected(object sender, SqlDataSourceStatusEventArgs e)
    {
        Label3.Text = "Выбрано: " + e.AffectedRows;
    }
    protected void cbxFilter_CheckedChanged(object sender, EventArgs e)
    {
        string TmpStr = "select * from ApSpdAtlas ";
        string AndStr = "";
        string WhereStr = "where ";
        tbxSurname.Enabled = cbxFilter.Checked;
        tbxCity.Enabled = cbxFilter.Checked;
        tbxAdress121.Enabled = cbxFilter.Checked;
        tbxKross.Enabled = cbxFilter.Checked;
        tbxGrebenka.Enabled = cbxFilter.Checked;
        tbxModem.Enabled = cbxFilter.Checked;
        tbxTelefon.Enabled = cbxFilter.Checked;
        btnFilterApply.Enabled = cbxFilter.Checked;
        // соберем запрос из заданных условий 
        if (cbxFilter.Checked == true) {
        if (tbxSurname.Text != "")
        {
            TmpStr = TmpStr + WhereStr + "(Surname like '" + tbxSurname.Text + "%')";
            AndStr = " and ";
            WhereStr = "";
        };
        if (tbxAdress121.Text != "")
        {
            TmpStr = TmpStr + WhereStr + AndStr + "(Address_x_121 like '" + tbxAdress121.Text + "%')";
            AndStr = " and ";
            WhereStr = "";
        };
        if (tbxCity.Text != "")
        {
            TmpStr = TmpStr + WhereStr + AndStr + "(City like '" + tbxCity.Text + "%')";
            AndStr = " and ";
            WhereStr = "";
        };
        if (tbxKross.Text != "")
        {
            TmpStr = TmpStr + WhereStr + AndStr + "(Kross like '" + tbxKross.Text + "%')";
            AndStr = " and ";
            WhereStr = "";
        };
        if (tbxGrebenka.Text != "")
        {
            TmpStr = TmpStr + WhereStr + AndStr + "(Grebenka like '" + tbxGrebenka.Text + "%')";
            AndStr = " and ";
            WhereStr = "";
        };
        if (tbxModem.Text != "")
        {
            TmpStr = TmpStr + WhereStr + AndStr + "(Modem like '" + tbxModem.Text + "%')";
            AndStr = " and ";
            WhereStr = "";
        };
        if (tbxTelefon.Text != "")
        {
            TmpStr = TmpStr + WhereStr + AndStr + "(Telefon like '" + tbxTelefon.Text + "%')";
            AndStr = " and ";
            WhereStr = "";
        };
            }
        dsApAtlas.SelectCommand = TmpStr;
        dsApAtlas.DataBind();
    }
    protected void btnFilterApply_Click(object sender, EventArgs e)
    {
        cbxFilter_CheckedChanged(sender, e);
    }
    protected void gvApAtlas_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void dsMon400_AP_Selected(object sender, SqlDataSourceStatusEventArgs e)
    {
        //Context.Request.QueryString["surname"] 
    }
}
